#include <plib.h> // Adds support for PIC32 Peripheral Library functions and macros


#define SYS_FREQ (80000000)
void DelayMs(unsigned int msec)
{
unsigned int tWait, tStart;
tWait=(SYS_FREQ/2000)*msec;
tStart=ReadCoreTimer();
while((ReadCoreTimer()-tStart)<tWait); // wait for the time to pass
}
int main(void)
{
/* LED setup - Turn off leds before configuring the IO pin as output */
mPORTDClearBits(BIT_0 | BIT_1 | BIT_2); // same as LATDCLR = 0x0007
/* Set RD0, RD1 and RD2 as outputs */
mPORTDSetPinsDigitalOut(BIT_0 | BIT_1 | BIT_2 ); // same as TRISDCLR = 0x0007
/* endless loop */
while(1)
{
DelayMs(100);
mPORTDToggleBits(BIT_0); // toggle LED0 (same as LATDINV = 0x0001)
DelayMs(100);
mPORTDToggleBits(BIT_1); // toggle LED1 (same as LATDINV = 0x0002)
DelayMs(100);
mPORTDToggleBits(BIT_2); // toggle LED2 (same as LATDINV = 0x0004)
};
return 0;
}